package 下一个更大元素Ⅱ;

import java.util.Arrays;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 下一个更大元素 II
 * @date 2022/11/26 17:08
 */
public class Demo503 {
    public static void main(String[] args) {
       int[] num= {1,2,1};
        int[] ints = nextGreaterElements(num);
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }
    }
    public static int[] nextGreaterElements(int[] nums) {
         int[] res=new int[nums.length];
          Arrays.fill(res,-1);
        for (int i = 0; i < nums.length; i++) {
             int j=(i+1)%nums.length;
             while (j!=i){
                if(nums[j]>nums[i]){
                    res[i]=nums[j];
                    break;
                }
                j=(j+1)%nums.length;
             }
        }
        return res;
    }
}
